package com.txm.qqcommon;

import java.io.File;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Arrays;

public class File_ implements Serializable {
    private static final long serialVersionUID = 1L;

    private String fileName;
    private long fileSize;
    private byte[] dataCut;
    private long dataCut_size;
    long total_read = 0;
    private double transferCompleted = 0;
    /**
     * status：
     * 0 开始 ;
     * 1 传输中 ;
     * -1 已完成 ;
     */
    private int status = 0;

    public File_(File file) {
        this.fileName = file.getName();
        this.fileSize = file.length();
    }

    public File_(String fileName, int fileSize, byte[] dataCut) {
        this.fileName = fileName;
        this.fileSize = fileSize;
        this.dataCut = dataCut;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public long getDataCut_size() {
        return dataCut_size;
    }

    public void setDataCut_size(long dataCut_size) {
        this.dataCut_size = dataCut_size;
        setTotal_read();
    }

    public long getTotal_read() {
        return total_read;
    }

    public String getProgress() {
        return "当前文件传输进度：" + new DecimalFormat("0.00").format(transferCompleted) + "%";
    }

    public void setTotal_read() {
        total_read += dataCut_size;
        if (total_read == 1024) {
            status = 0;
        }
        if (total_read > 1024 && total_read < fileSize) {
            status = 1;
        }
        if (total_read == fileSize) {
            status = -1;
        }
        transferCompleted = ((double) total_read / fileSize) * 100;
    }

    public double getTransferCompleted() {
        return transferCompleted;
    }

    public void setTransferCompleted(int transferCompleted) {
        this.transferCompleted = transferCompleted;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public long getFileSize() {
        return fileSize;
    }

    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }

    public byte[] getDataCut() {
        return dataCut;
    }

    public void setDataCut(byte[] dataCut) {
        this.dataCut = dataCut;
    }

    @Override
    public String toString() {
        return "File_{" +
                "fileName='" + fileName + '\'' +
                ", fileSize=" + fileSize +
                ", dataCut_size=" + dataCut_size +
                ", total_read=" + total_read +
                ", transferCompleted=" + transferCompleted +
                ", status=" + status +
                '}';
    }
}
